<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>骨医快线</title>
    <link href="../../../css/mui.plus.css" rel="stylesheet" />
    <style>
    	.mui-table-view-chevron .mui-table-view-cell {
    		padding-right: 15px;
    	}
    	span.pat-status1, span.pat-status2 {
		    padding: 0 3px;
    		margin-left: 5px;
		    border: 1px solid #aaa;
		    border-radius: 5px;
		    font-size: 12px;
		    color: #30B497;
		}
		span.pat-status2 {
			color: #999;
		}
		.mui-table-view:after {
			height: 0;
		}
		.pat-btn {
			margin: 25px 20%;
		}
		.pat-btn>.mui-btn {
			padding: 6px 0;
		}
    </style>
</head>
<body>
	<header class="mui-bar mui-bar-nav oe-pri-bar">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">老年髋部骨折项目</h1>
	</header>
	
    <div class="mui-content oe-home" id="refreshContainer">
	        <div class="pat-btn">
	            <button id="btn-create" type="button" class="mui-btn mui-btn-primary mui-btn-block">新建病例</button>
	        </div>
	        
	        <div class="oe-divide-block">
	        	
	        </div>
	        
	        <div class="oe-title-line">已建病例报告</div>
	        <ul class="mui-table-view mui-table-view-chevron oe-list1" id="list-case">
	            <!--<li class="mui-table-view-cell">
					<div class="mui-slider-right mui-disabled">
						<a class="mui-btn mui-btn-red">删除</a>
					</div>
					<div class="mui-slider-handle">
						加载中...
					</div>
				</li>-->
				<div class="oe-emp">
					<img src="../../../images/blank_page/empty-helper@2x.png"/>
				</div>
	        </ul>
	        
	        <div style="position: fixed;bottom: 0;right: 0;left: 0;">
				<p style="text-align: center;">PC端有更多实用功能<br />欢迎访问www.orthexpress.com</p>
			</div>
    </div>
    
	<script id="tmp-case" type="text/html">
		{{each data as v i}}
				<li class="mui-table-view-cell" data-caseid="{{v.case_id}}"
					data-inhos="{{v.rec_status === 'IN_HOS' ? 'true' : 'false'}}">
					<div class="mui-slider-right mui-disabled">
						<a class="mui-btn mui-btn-red" data-caseid="{{v.case_id}}">删除</a>
					</div>
			        <div class="mui-slider-handle">
			        	<div class="first-line">
				            <span>{{v.case_admission_name}}</span>
				            <span>{{v.rec_sexcase_admission_sex}}</span>
				            <span>{{v.case_admission_age}}</span>
				            <span>{{v.case_admission_broke_type}}</span>
				        </div>
				        <div class="second-line">
				        	<span class="date">{{v.case_ctime}}</span>
				        </div>
			        </div>
			    </li>
		{{/each}}
	</script>
    <script src="../../../js/mui.min.js"></script>
    <script src="../../../js/app.js"></script>
    <script src="../../../js/lib/template.js"></script>
    <script>
		(function($, a){
			var wv,
				caseId,
				html,
				tmpData;
				 
			window.addEventListener('refreshCase', function(){
				getCaseList(wv.data.actor_id)
			})
			 
			$('#list-case').on('tap', 'li', function(){
				var self = this;
				
				$.openWindow({
					url: 'case.html',
					waiting: {
						autoShow: false
					},
					extras: {
						case_id : this.dataset.caseid,
						action_type: 'check'
					}
				});
			});
			
			$('#list-case').on('tap', '.mui-btn-red', function(){
				var self = this;
				var li = self.parentNode.parentNode;
				$.confirm('确认删除该病历？', '骨医快线', ['确认','取消'], function(e) {
					if (e.index == 0) {
						li.parentNode.removeChild(li);
						deleteCaseById(self.dataset.caseid);
					} else {
						setTimeout(function() {
							$.swipeoutClose(li);
						}, 0);
					}
				});
			});
			
			$.plusReady(function(){
				wv = plus.webview.currentWebview();
						
				createCase(wv.data.actor_id, wv.data.actor_hospital);
				getCaseList(wv.data.actor_id)
				
				$('.mui-content').on('tap', '#btn-create', function(){
					
					$.openWindow({
						url: 'case.html',
						waiting: {
							autoShow: false
						},
						extras: {
							case_id : caseId,
							action_type: 'create'
						}
					});
				});
				 
			});
			
			var createCase = function(case_actor_id, case_admission_hospital){
				app.net.post('c_old_man_hip_broke_prj_case_test/create', {case_actor_id: case_actor_id, case_admission_hospital: case_admission_hospital}, function(data){
					if(data && data.code === '100')caseId = data.data.case_id;
				});
			} 
			
			var getCaseList = function(actor_id){
				app.net.get('c_old_man_hip_broke_prj_case_test/show_list', {actor_id:actor_id}, function(data){
					if(data && data.code === '100'){  
						tmpData = data;
						html = template('tmp-case', tmpData);
						document.getElementById("list-case").innerHTML = html
					}
				});
			}
			
			var deleteCaseById = function(case_id){
				app.net.post('c_old_man_hip_broke_prj_case_test/delete', {case_id: case_id}, function(data){
					if(data && data.code === '100'){  
						$.toast('删除成功')
					}
				});
			}
			
		}(mui, app));
	</script>
</body>
</html>